var tabHeight;
$(function(){
	tabHeight = $(window).height()-$('#navbar').height()-$('#tab_tablist').height()-64-15;
	$('#menus').delegate("a","click",function(){showNewTab(this);});
	var contentId = 'tab_home_content';
	var menu = '首页';
	var tabId = 'tab_home';
	var url = headpage;
	var id = '-1';
	$('#mainDiv').append(
			'<ul class="nav nav-tabs" role="tablist" id="tab_tablist">\
				<li role="presentation">\
				 <a href="#'+contentId+'" aria-controls="'+contentId+'" title="'+menu+'" role="tab" data-toggle="tab" id='+tabId+' class="tab_menu">'+menu+'</a>\
				</li>\
			</ul>\
			<div class="tab-content content-full" id="tab_content" > \
			<div role="tabpanel" class="tab-pane full-content" id="'+contentId+'" style="height: 100%;" >\
				<iframe frameborder="0" width="100%" height="100%" src="'+url+'" id="content_iframe_home"/>\
			</div>\
			</div>'		
		);
	contentHeight();
//	new event 
	$("#hidemenu").hide();
	$("#navbar-hide").click(function(){
		$("#navbar").fadeToggle();
		$("#hidemenu").fadeToggle();
	});
	$("#navbar-show").click(function(){
		$("#navbar").fadeToggle();
		$("#hidemenu").fadeToggle();
	});
	$('#'+tabId).click();
});
//左侧菜单树JS,author:姜秉岩，time:2916.08.26

$(function(){
	var setting = {
		data: {
			simpleData: {
				enable: true
			}
		},
		view:{
			showIcon:false
		},
		callback: {
			beforeClick: function(treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("tree");
				if (treeNode.isParent) {
					zTree.expandNode(treeNode);
				} 
					return true;
			
			},
		 	onClick:zTreeOnClick
		 }
	};
 $.fn.zTree.init($("#tree"), setting, zNodes);
});
function zTreeOnClick(event, treeId, treeNode) {
	var id =treeNode.id;
	var menu =treeNode.name;
	var url = treeNode.file;

	if(!url || '' == url || '#' == url){
		return;
	}
	var tabId = "tab_"+id;
	if($('#'+tabId).size() == 0){
		var contentId = 'content_'+id;
		url = frmPrefix+url;
		$('#tab_tablist').append(
			'<li role="presentation">'+
			' <a href="#'+contentId+'" aria-controls="'+contentId+'" title="'+menu+'" role="tab" data-toggle="tab" id='+tabId+' class="tab_menu">'+menu+'</a>'+
			' <span class="glyphicon glyphicon-remove-circle tab-close" aria-hidden="true" id="btnClose_'+id+'" onclick="close_tab(this.id)" ></span>'+
			'</li>'
		);
		$('#tab_content').append(
			'<div role="tabpanel" class="tab-pane full-content" id="'+contentId+'" style="height: 100%;"></div>'
		);
		$('#content_'+id).append('<iframe frameborder="0" width="100%" height="100%" src="'+url+'"/>');
	}
	$('#'+tabId).click();
}

function showNewTab(obj){
	var id =$(obj).attr('id');
	var menu = $(obj).text();
	var url = $(obj).attr('date-info');
	if(!url || '' == url || '#' == url){
		return;
	}
	var tabId = "tab_"+id;
	if($('#'+tabId).size() == 0){
		var contentId = 'content_'+id;
		url = frmPrefix+url;
		$('#tab_tablist').append(
			'<li role="presentation">'+
			' <a href="#'+contentId+'" aria-controls="'+contentId+'" title="'+menu+'" role="tab" data-toggle="tab" id='+tabId+' class="tab_menu">'+menu+'</a>'+
			' <span class="glyphicon glyphicon-remove-circle tab-close" aria-hidden="true" id="btnClose_'+id+'" onclick="close_tab(this.id)" ></span>'+
			'</li>'
		);
		$('#tab_content').append(
			'<div role="tabpanel" class="tab-pane full-content" id="'+contentId+'" style="height: 100%;"></div>'
		);
		$('#content_'+id).append('<iframe frameborder="0" width="100%" height="100%" src="'+url+'"/>');
	}
	$('#'+tabId).click();
}

// 展示标签页
function showTab(obj){
	$('#changpass').modal('show');
//	var id = $(obj).attr('id');
//	var menu = $('#'+id).text();
//	var url = $('#'+id).attr('url');
//	var tabId = "tab_"+id;
//	var contentId = 'content_'+id;
//	url = frmPrefix+url;
//	if(0 == $('#'+tabId).size()){
//		$('#tab_tablist').append(
//			'<li role="presentation">'+
//			'	<a href="#'+contentId+'" aria-controls="'+contentId+'" role="tab" data-toggle="tab" id='+tabId+'>'+menu+'</a>'+
//			'	<button type="button" class="close tab-close" aria-label="Close" id="btnClose_'+id+'" onclick="close_tab(this.id)"'+
//			' ><span aria-hidden="true">&times;</span></button>'+
//			'</li>'
//		);
//		$('#tab_content').append(
//			'<div role="tabpanel" class="tab-pane full-content" id="'+contentId+'"></div>'
//		);
//		$('#content_'+id).append('<iframe frameborder="0" width="100%" height="93%" src="'+url+'"/>');
//	}
//	$('#'+tabId).click();
}

// 关闭tab页
function close_tab(id){
	$('#'+id).parent().remove();
	id = 'content'+id.substring(id.indexOf('_'));
	$('#'+id).remove();
	$('#tab_tablist').children().last().children().first().click();
}

